<!DOCTYPE HTML>
<html>

<head>
<meta charset="utf-8" />
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="<?php echo X_UA_COMPATIBLE; ?>" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="blank" />
<meta name="format-detection" content="telephone=no" />
<title><?php echo $this->page_title; ?></title>

<link type="text/css" rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/bootstrap.css?v=<?php echo G_VERSION_BUILD; ?>" />
<link type="text/css" rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/css/icon.css?v=<?php echo G_VERSION_BUILD; ?>" />
<link type="text/css" rel="stylesheet" href="<?php echo G_STATIC_URL; ?>/admin/css/login.css?v=<?php echo G_VERSION_BUILD; ?>" />
<script type="text/javascript">
    var G_INDEX_SCRIPT = "<?php echo G_INDEX_SCRIPT; ?>";
    var G_BASE_URL = "<?php echo base_url(); ?>/<?php echo rtrim(G_INDEX_SCRIPT, '/'); ?>";
    var G_USER_ID = "<?php echo $this->user_id; ?>";
    var G_POST_HASH = "";
    var G_PRIVATEKEY = "<?php echo G_PRIVATEKEY; ?>";
    var G_IV = "<?php echo G_IV; ?>";
</script>
<?php if (is_array($this->_import_css_files)) { ?>
<?php foreach ($this->_import_css_files AS $import_css) { ?>
<link type="text/css" rel="stylesheet" href="<?php echo $import_css; ?>?v=<?php echo G_VERSION_BUILD; ?>" />
<?php } ?>
<?php } ?>
<?php if (is_array($this->_import_js_files)) { ?>
<?php foreach ($this->_import_js_files AS $import_js) { ?>
<script type="text/javascript" src="<?php echo $import_js; ?>?v=<?php echo G_VERSION_BUILD; ?>" ></script>
<?php } ?>
<?php } ?>
<script type="text/javascript" src="<?php echo G_STATIC_URL; ?>/js/slide_captcha/gt.js"></script>
<script src="<?php echo G_STATIC_URL; ?>/js/crypto-js.js"></script>
</head>

<body>
<div class="aw-login">
    <div class="mod center-block">
        <h1><img src="<?php echo G_STATIC_URL; ?>/admin/img/wecenter-logo.png" alt="" /></h1>

        <form role="form" id="login_form"  onsubmit="return false" action="admin/ajax/login_process/" method="post">
            <?php if ($_GET['url']){ ?>
            <input type="hidden" name="url" value="<?php echo htmlspecialchars($_GET['url']); ?>">
            <?php } ?>

            <div class="alert alert-danger collapse error_message"></div>

            <div class="form-group">
                <label><?php _e('用户名'); ?></label>
                <input type="text" class="form-control" placeholder="<?php _e('用户名'); ?>" value="<?php echo $this->user_info['user_name']; ?>" disabled="disabled" />
                <i class="icon icon-user"></i>
            </div>
            <div class="form-group">
                <label><?php _e('密码'); ?></label>
                <input type="password" class="form-control" placeholder="<?php _e('密码'); ?>" type="password" id="aw-login-user-password" onkeydown="if (event.keyCode == 13) { document.getElementById('login_submit').click(); };" autofocus/>
                <input id="aw-login-user-repassword" type="hidden" name="password" value="" />
                <i class="icon icon-lock"></i>
            </div>
            <?php if (get_setting('admin_login_seccode') == 'Y') { ?>
            <div class="form-group">
                <label><?php _e('验证码'); ?></label>
                <div class="row">
                  <!-- <div class="col-xs-5">
                    <input type="text" class="form-control" name="seccode_verify" onkeydown="if (event.keyCode == 13) { document.getElementById('login_submit').click(); };" maxlength="4" />
                  </div>
                  <div class="col-xs-4 col-xs-offset-1">
                    <img src="" class="verification" id="captcha" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" />
                  </div> -->
                    <div class="col-xs-5 embed-captcha"></div>
                    <p class="wait">正在加载验证码......</p>
                    <input type="hidden" name="client_type" value="web">
                    <input type="hidden" name="gt_status" id='gt_status' value="0">
                    <input type="hidden" name="gt_user" id='gt_user' value="0">
                </div>
            </div>
            <?php } ?>
            <button type="submit" class="btn btn-primary" id="login_submit" ><?php _e('登录'); ?></button>
        </form>

        <h2 class="text-center text-color-999">巨牛 Admin Control</h2>
    </div>
</div>
<script type="text/javascript">
<?php if (get_setting('admin_login_seccode') == 'Y') { ?>
var handlerEmbed = function (captchaObj) {
    $('#login_submit').click(function(){
        var validate = captchaObj.getValidate();
        if (!validate) {
            alert("请先完成验证");
            return false;
        } else{
            $('#aw-login-user-repassword').val(encrypt_pass($('#aw-login-user-password').val()));
            AWS.ajax_post($('#login_form'), AWS.ajax_processer, 'error_message');
            captchaObj.reset(); // 调用该接口进行重置
            return false;
        }
    });
    // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
    captchaObj.appendTo(".embed-captcha");
    captchaObj.onReady(function () {
        $(".wait").css('display','none');
    });
};

$.ajax({
    // 获取id，challenge，success（是否启用failback）
    url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
    type: "get",
    dataType: "json",
    success: function (data) {
        var dataObj = eval('(' + data.rsm + ')');
        if(dataObj.success != 1 || data.err.gt_status != 1){
            alert("极验校验失败,请刷新页面重新校验！");
            return false;
        }
        $("#gt_user").val(data.err.gt_user);
        $("#gt_status").val(data.err.gt_status);
        // 使用initGeetest接口
        // 参数1：配置参数
        // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
        initGeetest({
            gt: dataObj.gt,
            challenge: dataObj.challenge,
            new_captcha: dataObj.new_captcha,
            offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
            product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
            width: '100%' // 设置按钮宽度, 与父元素宽度一致
        }, handlerEmbed);
    }
});
<?php }else{ ?>
    $('#login_submit').click(function(){
        $('#aw-login-user-repassword').val(encrypt_pass($('#aw-login-user-password').val()));
        AWS.ajax_post($('#login_form'), AWS.ajax_processer, 'error_message');
        return false;
    });
<?php } ?>
function encrypt_pass(pass) {
    key = CryptoJS.enc.Utf8.parse(G_PRIVATEKEY);// 秘钥
    var iv= CryptoJS.enc.Utf8.parse(G_IV);//向量iv
    var encrypted = CryptoJS.AES.encrypt(pass, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7});
    return encrypted.toString();
}
</script>
